/*
  根据api版本判断环境，调用不同的方法
  不支持1.1 就是word 2013

  export 一个方法 在执行时判断 调用什么方法
*/
const OfficeUtils = {
  insertOoxmlAfterParagraph: (ooxml) => {
    Office.context.document.setSelectedDataAsync(
      ooxml,
      {
        coercionType: Office.CoercionType.Ooxml
      },
      function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {

        }
      });
  },
  insertHtmlAfterParagraph: (html) => {
    Office.context.document.setSelectedDataAsync(
      html,
      {
        coercionType: Office.CoercionType.Html
      },
      function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {

        }
      });
  },
  insertImage: (base64) => {
    Office.context.document.setSelectedDataAsync( // TODO 待验证支持版本未知 https://docs.microsoft.com/zh-cn/javascript/api/office/office.platformtype?view=office-js
      base64.split(',')[1],
      {
        coercionType: Office.CoercionType.Image
      },
      function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {

        }
      });
  },
  insertTable: (tableData) => {
    Office.context.document.setSelectedDataAsync(
      tableData,
      {coercionType: Office.CoercionType.Table},
      function (result) {
        var error = result.error
        if (result.status === Office.AsyncResultStatus.Failed) {
        }
    });
  }
}

export default OfficeUtils
